<html>
<head><meta charset="utf-8"><title>Incremental performance of THIR unsafety checker · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html">Incremental performance of THIR unsafety checker</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="248393794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248393794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248393794">(Aug 04 2021 at 19:05)</a>:</h4>
<p>Enabling the THIR unsafety checker leads to a big (5.86%) perf regression in the <code>style-servo-check run incr-patched: b9b3e592dd cherry picked</code> benchmark (see the <a href="https://perf.rust-lang.org/compare.html?start=2939249f294dd54a9ce78a8ee1f2922a44e7fb7c&amp;end=56a58d347b1c7dd0c2984b8fc3930c408e26fbc2">perf comparison</a>). The query diff reveals that the borrow checker gets ran 126% more, but I don't know why, and I don't know how I can investigate this. Does anyone have any advice on how I could tackle this?</p>



<a name="248415013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248415013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248415013">(Aug 04 2021 at 22:05)</a>:</h4>
<p>Can it come from the fact that the MIR-based unsafety checker is disabled in those runs?</p>



<a name="248416768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248416768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248416768">(Aug 04 2021 at 22:24)</a>:</h4>
<p>Can you run the borrowck more because you don't run the MIR-based unsafeck? That sounds counterintuitive</p>



<a name="248417046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248417046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248417046">(Aug 04 2021 at 22:26)</a>:</h4>
<p>The only idea I had was that since MIR building <code>enforce()</code>s THIR unsafeck, maybe if THIR unsafety checking changes it marks the MIR build query as changed, but I don't see how that would be the case since <code>thir_check_unsafety</code> returns <code>()</code></p>



<a name="248417145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248417145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248417145">(Aug 04 2021 at 22:28)</a>:</h4>
<p>Mhh, why does <code>thir_check_unsafety</code> have <code>cache_on_disk_if { true }</code>? I probably copied that from the MIR unsafeck query.</p>



<a name="248418150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248418150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Smittyvb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248418150">(Aug 04 2021 at 22:41)</a>:</h4>
<p>Running thir-unsafeck can cause MIR to be built for constants -- perhaps that's causing it somehow?</p>



<a name="248418242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248418242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248418242">(Aug 04 2021 at 22:42)</a>:</h4>
<p>They should be built anyway, no?</p>



<a name="248418377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248418377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Smittyvb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248418377">(Aug 04 2021 at 22:45)</a>:</h4>
<p><code>mir_const</code> has <code>no_hash</code>, i think that might cause it to be built twice</p>



<a name="248418391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248418391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Smittyvb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248418391">(Aug 04 2021 at 22:45)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/d54fbb98555c107fb62fb5ae1a5b8f4fc6ed3edc/compiler/rustc_middle/src/query/mod.rs#L269-L280">https://github.com/rust-lang/rust/blob/d54fbb98555c107fb62fb5ae1a5b8f4fc6ed3edc/compiler/rustc_middle/src/query/mod.rs#L269-L280</a></p>



<a name="248418732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248418732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248418732">(Aug 04 2021 at 22:50)</a>:</h4>
<p>IIRC <code>no_hash</code> means that <code>mir_const</code> will be considered changed if any of its dependencies is changed. Does <code>mir_const</code> depend on <code>thir_check_unsafety</code> somehow?</p>



<a name="248420846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248420846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Smittyvb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248420846">(Aug 04 2021 at 23:15)</a>:</h4>
<p>Building the MIR involves getting the THIR in order to make it into MIR but I don't know if that involves unsafety checking it</p>



<a name="248421007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248421007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248421007">(Aug 04 2021 at 23:17)</a>:</h4>
<p>It does, because after MIR building we drop the THIR to reduce the memory impact</p>



<a name="248421443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248421443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Smittyvb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248421443">(Aug 04 2021 at 23:22)</a>:</h4>
<p>then perhaps removing <code>no_hash</code> from <code>mir_const</code> could help with perf?</p>



<a name="248421720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Incremental%20performance%20of%20THIR%20unsafety%20checker/near/248421720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Incremental.20performance.20of.20THIR.20unsafety.20checker.html#248421720">(Aug 04 2021 at 23:25)</a>:</h4>
<p>AFAICT <code>mir_const</code> only depends on <code>mir_built</code> which is not <code>no_hash</code>?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>